#include "CompilerAndRunner.hpp"
#include"../Common/httplib.h"
#include <iostream>

int main(int argc, char *argv[])
{
  if(argc!= 2)
  {
    std::cout<<"Usage: "<<argv[0]<<" port"<<std::endl;
    return 1;
  }
  
  httplib::Server server;

  server.Post("/compile_and_run", [](const httplib::Request &req, httplib::Response &res) {
    std::string str_json_in = req.body;
    std::string str_json_out;
    OJ::CompilerAndRunner::start(str_json_in,str_json_out);
    res.set_content(str_json_out, "application/json,charset=UTF-8");
  });

  server.listen("0.0.0.0", std::stoi(argv[1]));
  return 0;
}